package test.study.java.jol.samples;

import lombok.extern.slf4j.Slf4j;
import org.openjdk.jol.info.ClassLayout;
import org.openjdk.jol.vm.VM;

@Slf4j
public class JOLSample_15_IdentityHashCode {

    /*
     * The example for identity hash code.
     *
     * The identity hash code, once computed, should stay the same.
     * HotSpot opts to store the hash code in the mark word as well.
     * You can clearly see the hash code bytes in the header once
     * it was computed.
     */

    public static void main(String[] args) {
        log.info(VM.current().details());

        final A a = new A();

        ClassLayout layout = ClassLayout.parseInstance(a);

        log.info("**** Fresh _3_object");
        log.info(layout.toPrintable());

        log.info("hashCode: " + Integer.toHexString(a.hashCode()));
        log.info("");

        log.info("**** After identityHashCode()");
        log.info(layout.toPrintable());
    }

    public static class A {
        // no fields
    }
}
